import { $event } from '/utils'
import { checkAuth } from '/store/actions'
import { getServer } from '/store/mutations'
import { GlobalData } from '/store/state'

Page({
  data: {
    isFullScreen: GlobalData.isFullScreen,
    verification: {} as DomoUserVerification,
    form: {} as DomoUserVerification,
    type: '' as string,
  },
  async onLoad({ type }: { type: string }) {
    this.setData({
      isFullScreen: GlobalData.isFullScreen,
    })
    if (type) {
      wx.setNavigationBarTitle({
        title: type === 'user' ? '个人认证' : '企业认证',
      })
    }
    $event.on('after:login', this, async () => {
      this.getUserInfo()
    })
    await checkAuth()
    this.getUserInfo()
  },
  getUserInfo() {
    const server = getServer()
    const user = wx.getStorageSync(`${server}/logged`).data || {}
    this.setData({
      verification: user.verification,
    })
  },
  previewImage(e: any) {
    const {
      target: {
        dataset: { src },
      },
    } = e
    wx.previewImage({
      current: '0',
      urls: [src],
    })
  },
  reVerify() {
    wx.showActionSheet({
      itemList: ['个人认证', '机构认证'],
      success: ({ tapIndex }) => {
        wx.navigateTo({
          url: `/mine/add-${tapIndex === 0 ? 'user' : 'org'}-verification/add-${tapIndex === 0 ? 'user' : 'org'
            }-verification?isReVeiryfied=true`,
        })
      },
    })
  },
})
